package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.EmployeeDTO;
import com.sky.dto.EmployeePageQueryDTO;
import com.sky.dto.PasswordEditDTO;
import com.sky.entity.Employee;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface EmployeeMapper {

    /**
     * 根据用户名查询员工
     */
    @Select("select * from employee where username = #{username}")
    Employee getByUsername(String username);


    @Insert("insert into employee (username,name,phone,sex,password,id_number,status,create_time,update_time,create_user,update_user) " +
            "values (#{username},#{name},#{phone},#{sex},#{password},#{idNumber},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    @AutoFill(value = OperationType.INSERT)
    void save(Employee employee);


    Page<Employee> empList(EmployeePageQueryDTO employeePageQueryDTO);


    @Update("update  employee set status=#{status} where id=#{id}")
    void setStatus(Integer status, Integer id);

    @Select("select * from employee where id=#{id}")
    Employee getEmp(Integer id);

    @Update("update employee set name=#{name},phone=#{phone},sex=#{sex},username=#{username},id_number=#{idNumber},update_time=#{updateTime},update_user=#{updateUser} where id=#{id}")
    @AutoFill(value =OperationType.UPDATE)
    void updateEmp(Employee employee);

    @Update("update employee set password=#{newPassword} where id=#{empId} and password=#{oldPassword}")
    void editPassword(PasswordEditDTO passwordEditDTO);
}
